import Vue from "vue";

/**
 * px 单位换算为 vw 单位
 */
Vue.filter("px2vw", function(val) {
  return (val / 1920) * 100 + "vw";
});

export function formatPx2vw(str) {
  if (typeof str === "number" && !isNaN(str)) {
    return str / 1920 * 100 + "vw"
  } else {
    return str.replace(/(\d+)(\.\d+)?px\b/g, function(matched, $1) {
      return $1 / 1920 * 100 + "vw"
    })
  }
}

Vue.prototype.$px2vw = formatPx2vw;
